Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host/sm: Add CSIS SIRK encryption #1635

Merged
merged 1 commit into from
Oct 9, 2023

Conversation

m-gorecki
Copy link
Contributor

This adds functions and algorithms to encrypt and decrypt SIRK from Coordinated Set Identification Service.

This also adds API to resolve RSI. Application can use it to find devices that are part of Coordinated Set.

@m-gorecki m-gorecki force-pushed the sm_csis branch 2 times, most recently from e62627e to 292cc25 Compare October 6, 2023 15:12
@m-gorecki m-gorecki marked this pull request as draft October 6, 2023 15:15
@m-gorecki m-gorecki marked this pull request as ready for review October 6, 2023 17:10
Copy link
Contributor

@andrzej-kaczmarek andrzej-kaczmarek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, just few style comments

@@ -2910,4 +2910,109 @@ ble_sm_create_chan(uint16_t conn_handle)
return chan;
}

#if MYNEWT_VAL(BLE_SM_SC)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd add BLE_SM_CSIS_SIRK to enable everything related to handling CSIS SIRK and move this to ble_sm_csis.c

also mark syscfg as experimental since we may want to move it to some place more appropriate and rename in future with addition of le audio code.

return rc;
}

if (memcmp(local_hash, hash, 3) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better write this as:

if (memcmp(local_hash, hash, 3)) {
    return BLE_HS_EAUTHEN;
}

return 0;

this way return value in case of success is at the very end of function as expected

* We assume that 16 bytes is enough and return error if passed len value is greater
* than that */
if ((n_len > 16) || (p_len > 16)) {
return BLE_HS_EUNKNOWN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

einval

* We assume that 16 bytes is enough and return error if passed len value is greater
* than that */
if (m_len > 16) {
return BLE_HS_EUNKNOWN;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

einval

return rc;
}
/* Two MSBs of prand shall be equal to 0 and 1 */
prand[2] &= ~(0x80);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: &= ~0xc0 -> we want to change 2 bits so clear 2 bits, we write it like this in code that calculates rpa


memset(&key_sec, 0, sizeof(key_sec));
key_sec.peer_addr.type = peer_addr.type;
memcpy(key_sec.peer_addr.val, peer_addr.val, 6);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key_sec.peer_addr = peer_addr

return rc;
} else if (!value_sec.ltk_present) {
return BLE_HS_ENOENT;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be only done if sirk is encrypted

@@ -111,6 +113,8 @@ struct ble_sm_io {
};

int ble_sm_sc_oob_generate_data(struct ble_sm_sc_oob_data *oob_data);
int ble_sm_csis_resolve_rsi(ble_addr_t peer_addr, uint8_t *rsi,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ble_addr_t *peer_addr
const uint8_t *rsi
const uint8_t *sirk

@m-gorecki m-gorecki force-pushed the sm_csis branch 2 times, most recently from 368fb2a to 9feb506 Compare October 9, 2023 08:42
@m-gorecki m-gorecki force-pushed the sm_csis branch 2 times, most recently from cb67d52 to d983027 Compare October 9, 2023 09:48
This adds functions and algorithms to encrypt and decrypt
SIRK from Coordinated Set Identification Service.

This also adds API to resolve RSI. Application can use it
to find devices that are part of Coordinated Set.
@andrzej-kaczmarek andrzej-kaczmarek merged commit f2cb1ec into apache:master Oct 9, 2023
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants